import java.awt.Point;
import java.util.ArrayList;

public class Path implements Comparable{
	
	private ArrayList<Point> pointList;
	private Point desired;
	
	//Takes in a list of points in the path and a desired final position
	public Path (ArrayList<Point> pointList, Point desired){
		this.pointList = pointList;
		this.desired = desired;
	}
	
	public void addPoint(Point point){
		pointList.add(point);
	}
	
	public Point getPointAt(int i){
		return pointList.get(i);
	}
	
	public ArrayList<Point> getPointList(){
		return pointList;
	}
	
	public void setDesired(Point point){
		desired = point;
	}
	
	public Point getDesired(){
		return desired;
	}
	public int size(){
		return pointList.size();
	}

	
	public int compareTo(Object other) {
		
		//Compares paths based on length
		/*double distance = getLength();
		double otherDistance = ((Path)other).getLength();
		
		if(distance > otherDistance){
			return 1;
		}
		else if(distance < otherDistance){
			return -1;
		}
		else if(distance == otherDistance){
			return 0;
		}
		return 0;*/
		
		//Compares paths based on final distance from objective point
		double distance = distanceToDesired();
		double otherDistance = ((Path)other).distanceToDesired();
		
		if(distance > otherDistance){
			return 1;
		}
		else if(distance < otherDistance){
			return -1;
		}
		else if(distance == otherDistance){
			return 0;
		}
		return 0;
	}
	
	//False if any corresponding point in the path is within a range of 
	//that of another path
	public boolean check(Path other){
		
		ArrayList<Point> otherList = other.getPointList();
		
		for(int i=0; i<pointList.size(); i++){
			if(Math.abs(pointList.get(i).x - otherList.get(i).x) < 50 
					&& Math.abs(pointList.get(i).y - otherList.get(i).y) < 50 ){
				return false;
			}
		}
		return true;
	}
	
	//Computes path length using triangles
	public double getLength(){
		double distance = 0;
		for(int i=0; i+1<pointList.size(); i++){
			distance += Math.sqrt(Math.pow((pointList.get(i).x - pointList.get(i+1).x), 2) + Math.pow((pointList.get(i).y - pointList.get(i+1).y), 2));
		}
		return distance;
	}
	
	//Computes distance to the desired point in a path
	public double distanceToDesired(){
		double distance = 0;
		Point current = pointList.get(pointList.size()-1);
		distance = Math.sqrt(Math.pow((current.x - desired.x), 2) + Math.pow((current.y - desired.y), 2));
		return distance;
	}
	
	
}